<template>
	<view class="userinfo">
		<view class="form">
			<button class="avatar-wrap" open-type="chooseAvatar" @chooseavatar="onChooseAvatar">
				<view class="label"> 头像 </view>
				<view class="ipt">
					<img class="avatar" :src="apiUrl + userInfo.pic" />
					<uni-icons class="arrow-right" type="right" size="20"></uni-icons>
				</view>
			</button>
		</view>
		<view class="info_nickname">
			<view class="nickname_left"> 账号 </view>
			<view class="nickname_right">
				{{userInfo.account}}
			</view>
		</view>
		<view class="info_nickname">
			<view class="nickname_left"> 昵称 </view>
			<view class="nickname_right">
				<input v-model="userInfo.nickname" placeholder="请输入您的昵称" />
			</view>
		</view>
		<view class="info_nickname">
			<view class="nickname_left"> 性别 </view>
			<view class="nickname_right gender">
				
				<picker @change="examinationType" :value="index" :range="examinationTypeArray">
					<view class="uni-input">{{examinationTypeArray[index]}}</view>
				</picker>
				<uni-icons class="arrow-right" type="right" size="20" style="margin-top: 5rpx"></uni-icons>
			</view>
		</view>
		<view class="info_nickname">
			<view class="nickname_left"> 手机号 </view>
			<view class="nickname_right">
				<view class="showphone">
					{{ userInfo.mobile }}
				</view>
			</view>
		</view>
		<view class="info_nickname">
			<view class="nickname_left"> 邮箱 </view>
			<view class="nickname_right">
				<view class="showphone">
					{{ userInfo.email }}
				</view>
			</view>
		</view>
		<view class="btn-wrap">
			<button style="background-color: #27ba9b;color: #fff;" class="btn" @click="saveinfo">保存</button>
		</view>
	</view>
</template>

<script>
	// import  {getPhone}  from '../../utils/phoneNumber.js'
	import {
		apiUrl
	} from '@/config/config.js';

	export default {
		data() {
			return {
				cdnUrl: getApp().globalData.cdnUrl + 'static/img-my/userpicter.png',
				avatar: '',
				nickname: '',
				username: '',
				examinationTypeArray: ['男', '女', '隐私'],
				phone: '',
				apiUrl: apiUrl,
				userInfo: '',
				index: 1,
			}
		},
		onLoad() {
			this.getUserinfo()
		},
		methods: {
			saveinfo: function() {
				uni.request({
					url: this.apiUrl + '/api/user/update',
					data: this.userInfo,
					method: 'PUT',
					success: (res) => {
						uni.reLaunch({
							url: '/pages/mine/index' // 将'/pages/currentPage/currentPage'替换为当前页面的路径
						});
					}
				})
			},
			upload_file: function(e) {
				
			},
			getUserinfo() {
				uni.request({
					url: this.apiUrl + '/api/user/userInfo',
					data: {
						account: uni.getStorageSync('account_key')
					},
					method: 'GET',
					success: (res) => {
						if (res.data.code == '200') {
							this.userInfo = res.data.data
						} else {

						}
					}
				})
			},
			onChooseAvatar(res) {
				console.log(res)
				const {
					detail
				} = res
				this.upload_file(detail.avatarUrl)
				this.cdnUrl = detail.avatarUrl
			},
			// 绑定输入监听事件
			onName(event) {
				console.log(event)
				const {
					detail
				} = event
				this.username = detail.value
			},
			change(e) {
				console.log('e:', e)
			},
			examinationType(e) {
				console.log('picker发送选择改变，携带值为', e.detail.value)
				this.index = e.detail.value
			},
			onPhone(event) {
				console.log(event)
				const {
					detail
				} = event
				this.phone = detail.value
			}
		}
	}
</script>

<style lang="scss">
	button::after {
		border-top: none;
		border-left: none;
		border-right: none;
		border-radius: 0;
	}

	.userinfo {
		font-size: 34rpx;
		font-weight: 400;
		color: #333333;
		height: 100%;
		position: relative;

		.form {
			background-color: #ffffff;
		}

		.avatar-wrap {
			border: 0;
			background-color: #ffffff;
			height: 158rpx;
			display: flex;
			align-items: center;
			justify-content: space-between;
			padding: 0 32rpx;

			.avatar {
				margin-right: 10rpx;
			}

			.ipt {
				display: flex;
				align-items: center;
			}

			img {
				width: 118rpx;
				height: 118rpx;
			}
		}

		.info_nickname {
			border-bottom: 1px solid #e9e9e9;
			height: 112rpx;
			background: #ffffff;
			display: flex;
			align-items: center;
			justify-content: space-between;
			padding: 0 32rpx;
			// justify-content: space-between;

			.nickname_left {}

			.nickname_right {
				input {
					text-align: right;
				}
			}

			.gender {
				display: flex;
				align-items: center;
				justify-content: center;
			}
		}

		.btn-wrap {
			position: absolute;
			// bottom: 50rpx;
			margin-top: 50rpx;
			width: 100%;
			text-align: center;

			.btn {
				width: 690rpx;
				height: 88rpx;
			}
		}
	}
</style>